package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class Goods extends BaseDomain{

    public static final boolean STATE_NOMAL = false; //普通
    public static final boolean STATE_COMMEND = true; //推荐

    private String title;

    private BigDecimal price; //价格

    private Integer inventory; //库存

    private String coverUrl; //商品照片

    private String description; //商品描述

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;

    private GoodsType type; //类型

    private boolean state = STATE_NOMAL; //是否推荐

    public String getStateName() {
        return this.state?"推荐":"普通";
    }

    public Object getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("price", price);
        map.put("coverUrl", coverUrl);
        map.put("description", description);
        map.put("inventory", inventory);
        map.put("state", state);
        if (type != null) {
            map.put("typeId", type.getId());
        }
        return JSON.toJSONString(map);
    }

}